package GUI;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import core.model.Sugerencia;

import GUI.manager.VentanaFactory;
import GUI.manager.VentanaManager;

public class panelSugerenciasOtras extends javax.swing.JPanel implements
		ActionListener, ItemListener {

	private static final int OK_CANCEL_OPTION = 0;
	private static final int PLAIN_MESSAGE = 0;

	public panelSugerenciasOtras() {
		initComponents();
	}

	private void initComponents() {

		bSugerencias = new javax.swing.JButton();
		bTitulo = new javax.swing.JButton();
		eTipo = new javax.swing.JLabel();
		bOpciones = new javax.swing.JButton();
		botonSalir = new javax.swing.JButton();
		bCrearLista = new javax.swing.JButton();
		bBusqueda = new javax.swing.JButton();
		cTipo = new javax.swing.JComboBox();
		bAyuda = new javax.swing.JButton();
		etiquetaEntrada = new javax.swing.JLabel();
		etiquetaNick = new javax.swing.JLabel();
		bHistorial = new javax.swing.JButton();
		panelCentro = new javax.swing.JPanel();
		jTextField1 = new javax.swing.JTextField();
		eAsunto = new javax.swing.JLabel();
		eMensaje = new javax.swing.JLabel();
		jScrollPane1 = new javax.swing.JScrollPane();
		taMensaje = new javax.swing.JTextArea();
		bEnviar = new javax.swing.JButton();

		setBackground(new java.awt.Color(255, 255, 255));

		bSugerencias.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bSugerencias.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonSugerencias.png")); // NOI18N
		bSugerencias.setBorderPainted(false);
		bSugerencias.setBackground(new java.awt.Color(255, 255, 255));

		bTitulo.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/encabezadoMain.png")); // NOI18N
		bTitulo.setBorder(null);
		bTitulo.setBorderPainted(false);
		bTitulo.addActionListener(this);
		bTitulo.setBackground(new java.awt.Color(255, 255, 255));

		eTipo.setBackground(new java.awt.Color(255, 255, 255));
		eTipo.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eTipo.setForeground(new java.awt.Color(102, 102, 102));
		eTipo.setText("TIPO DE SUGERENCIA");

		bOpciones.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bOpciones.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonOpciones.png")); // NOI18N
		bOpciones.setBorderPainted(false);
		bOpciones.addActionListener(this);
		bOpciones.setBackground(new java.awt.Color(255, 255, 255));

		botonSalir.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/menu-salir.png")); // NOI18N
		botonSalir.setBorderPainted(false);
		botonSalir.addActionListener(this);
		botonSalir.setBackground(new java.awt.Color(255, 255, 255));

		bCrearLista.setBackground(new java.awt.Color(255, 255, 255));
		bCrearLista.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bCrearLista.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonCrearLista.png")); // NOI18N
		bCrearLista.setBorderPainted(false);
		bCrearLista.addActionListener(this);

		bBusqueda.setBackground(new java.awt.Color(255, 255, 255));
		bBusqueda.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bBusqueda.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonBusqueda.png")); // NOI18N
		bBusqueda.setToolTipText("");
		bBusqueda.setBorderPainted(false);
		bBusqueda.addActionListener(this);

		cTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
				"Productos", "Otras" }));
		cTipo.setSelectedIndex(1);
		cTipo.addItemListener(this);

		bAyuda.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bAyuda.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonAyuda.png")); // NOI18N
		bAyuda.setBorderPainted(false);
		bAyuda.addActionListener(this);
		bAyuda.setBackground(new java.awt.Color(255, 255, 255));

		etiquetaEntrada.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		etiquetaEntrada.setForeground(new java.awt.Color(243, 15, 120));
		etiquetaEntrada.setText("BIENVENIDO A LISTA DE LA COMPRA MAKER ");

		etiquetaNick.setBackground(new java.awt.Color(102, 102, 102));
		etiquetaNick.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		etiquetaNick.setText(panelPrincipal.nick);
		etiquetaNick.setToolTipText("");

		bHistorial.setBackground(new java.awt.Color(255, 255, 255));
		bHistorial.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bHistorial.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonHistorial.png")); // NOI18N
		bHistorial.setBorderPainted(false);
		bHistorial.addActionListener(this);

		panelCentro.setBackground(new java.awt.Color(255, 255, 255));

		jTextField1.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		jTextField1.setForeground(new java.awt.Color(102, 102, 102));

		eAsunto.setBackground(new java.awt.Color(255, 255, 255));
		eAsunto.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eAsunto.setForeground(new java.awt.Color(102, 102, 102));
		eAsunto.setText("ASUNTO");
		eAsunto.setToolTipText("");

		eMensaje.setBackground(new java.awt.Color(255, 255, 255));
		eMensaje.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eMensaje.setForeground(new java.awt.Color(102, 102, 102));
		eMensaje.setText("MENSAJE");
		eMensaje.setToolTipText("");

		taMensaje.setColumns(20);
		taMensaje.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		taMensaje.setForeground(new java.awt.Color(102, 102, 102));
		taMensaje.setRows(5);
		jScrollPane1.setViewportView(taMensaje);

		bEnviar.setBackground(new java.awt.Color(255, 255, 255));
		bEnviar.setFont(new java.awt.Font("Lucida Handwriting", 1, 14)); // NOI18N
		bEnviar.setForeground(new java.awt.Color(243, 15, 120));
		bEnviar.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonEnviar.png")); // NOI18N
		bEnviar.setBorder(null);
		bEnviar.addActionListener(this);

		org.jdesktop.layout.GroupLayout panelCentroLayout = new org.jdesktop.layout.GroupLayout(
				panelCentro);
		panelCentro.setLayout(panelCentroLayout);
		panelCentroLayout
				.setHorizontalGroup(panelCentroLayout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(panelCentroLayout
								.createSequentialGroup()
								.add(60, 60, 60)
								.add(panelCentroLayout
										.createParallelGroup(
												org.jdesktop.layout.GroupLayout.LEADING)
										.add(panelCentroLayout
												.createSequentialGroup()
												.add(12, 12, 12)
												.add(jScrollPane1,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
														505,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
										.add(eMensaje))
								.addContainerGap(52, Short.MAX_VALUE))
						.add(org.jdesktop.layout.GroupLayout.TRAILING,
								panelCentroLayout
										.createSequentialGroup()
										.addContainerGap(
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE).add(bEnviar)
										.add(242, 242, 242)));
		panelCentroLayout.setVerticalGroup(panelCentroLayout
				.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
				.add(panelCentroLayout
						.createSequentialGroup()
						.add(eMensaje)
						.addPreferredGap(
								org.jdesktop.layout.LayoutStyle.UNRELATED)
						.add(jScrollPane1,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
								156,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
						.add(24, 24, 24)
						.add(bEnviar,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
								39,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
						.addContainerGap(21, Short.MAX_VALUE)));
		org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
				this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
				.add(layout
						.createSequentialGroup()
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(layout
										.createSequentialGroup()
										.addContainerGap()
										.add(layout
												.createParallelGroup(
														org.jdesktop.layout.GroupLayout.LEADING)
												.add(layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.TRAILING)
														.add(bCrearLista,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																157,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
														.add(bBusqueda,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																155,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
														.add(bHistorial,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																157,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
														.add(bSugerencias,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																157,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
														.add(bOpciones,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																157,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
												.add(org.jdesktop.layout.GroupLayout.TRAILING,
														bAyuda,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
														157,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
										.add(layout
												.createParallelGroup(
														org.jdesktop.layout.GroupLayout.LEADING)
												.add(layout
														.createSequentialGroup()
														.add(35, 35, 35)
														.add(layout
																.createParallelGroup(
																		org.jdesktop.layout.GroupLayout.LEADING)
																.add(panelCentro,
																		org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																		org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																		Short.MAX_VALUE)
																.add(layout
																		.createSequentialGroup()
																		.add(eTipo)
																		.addPreferredGap(
																				org.jdesktop.layout.LayoutStyle.UNRELATED)
																		.add(cTipo,
																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																				314,
																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
																		.add(0,
																				0,
																				Short.MAX_VALUE))))
												.add(layout
														.createSequentialGroup()
														.add(93, 93, 93)
														.add(eAsunto)
														.addPreferredGap(
																org.jdesktop.layout.LayoutStyle.UNRELATED)
														.add(jTextField1,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																250,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
														.add(0, 0,
																Short.MAX_VALUE))))
								.add(layout.createSequentialGroup()
										.add(96, 96, 96).add(bTitulo)
										.add(44, 44, 44).add(botonSalir))
								.add(layout
										.createSequentialGroup()
										.add(84, 84, 84)
										.add(etiquetaEntrada)
										.add(46, 46, 46)
										.add(etiquetaNick,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												280,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
						.addContainerGap(
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE)));
		layout.setVerticalGroup(layout
				.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
				.add(layout
						.createSequentialGroup()
						.add(6, 6, 6)
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(bTitulo,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
										104,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
								.add(botonSalir))
						.add(6, 6, 6)
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.BASELINE)
								.add(etiquetaNick).add(etiquetaEntrada))
						.add(18, 18, 18)
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(layout
										.createSequentialGroup()
										.add(layout
												.createParallelGroup(
														org.jdesktop.layout.GroupLayout.BASELINE)
												.add(eTipo)
												.add(cTipo,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
														org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
										.add(73, 73, 73)
										.add(layout
												.createParallelGroup(
														org.jdesktop.layout.GroupLayout.BASELINE)
												.add(eAsunto)
												.add(jTextField1,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
														org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
										.add(18, 18, 18)
										.add(panelCentro,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
								.add(layout
										.createSequentialGroup()
										.add(bBusqueda,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bCrearLista,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bHistorial,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bSugerencias,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bOpciones,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bAyuda,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
						.addContainerGap(
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE)));
	}

	private javax.swing.JButton bAyuda;
	private javax.swing.JButton bBusqueda;
	private javax.swing.JButton bCrearLista;
	private javax.swing.JButton bEnviar;
	private javax.swing.JButton bHistorial;
	private javax.swing.JButton bOpciones;
	private javax.swing.JButton bSugerencias;
	private javax.swing.JButton bTitulo;
	private javax.swing.JButton botonSalir;
	private javax.swing.JComboBox cTipo;
	private javax.swing.JLabel eAsunto;
	private javax.swing.JLabel eMensaje;
	private javax.swing.JLabel eTipo;
	private javax.swing.JLabel etiquetaEntrada;
	private javax.swing.JLabel etiquetaNick;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JTextField jTextField1;
	private javax.swing.JPanel panelCentro;
	private javax.swing.JTextArea taMensaje;
	private JFrame actual;
	private JPanel estePanel = this;

	public void itemStateChanged(ItemEvent e) {
		if (e.getSource() == cTipo) {

			if (cTipo.getSelectedItem().equals("Productos")) {
				actual = (JFrame) UtilidadesGUI
						.getContenedorPrincipal(estePanel);
				actual.getContentPane().remove(0);
				actual.getContentPane().add(new panelSugerencias());
				actual.setPreferredSize(new Dimension(850, 630));
				actual.pack();
				actual.repaint();
				UtilidadesGUI.CentrarPantalla(actual);
			}

		}

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == bBusqueda) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelBusqueda());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}

		if (e.getSource() == bHistorial) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelHistorial());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bOpciones) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelOpciones());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bAyuda) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelAyuda());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bCrearLista) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelCrearLista());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bTitulo) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelPrincipal());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == botonSalir) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelSalir(20));
			actual.setPreferredSize(new Dimension(610, 330));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bEnviar) {
			if((jTextField1.getText().length()==0)||(taMensaje.getText().length()==0)){
				
				Icon icono = new ImageIcon("src/GUI/resources/error.gif");
				JOptionPane.showOptionDialog(null, "Introduce todos los campos",
						"Sugerencias otras", OK_CANCEL_OPTION, PLAIN_MESSAGE, icono,
						new Object[] { "ACEPTAR" }, null);
			}else{
			
			
			Icon iconoAceptar = new ImageIcon("src/GUI/resources/aceptar.gif");
			JOptionPane.showOptionDialog(null, "Sugerencia enviada con exito",
					"Sugerencias otras", OK_CANCEL_OPTION, PLAIN_MESSAGE, iconoAceptar,
					new Object[] { "ACEPTAR" }, null);
			Sugerencia sugerencia = new Sugerencia(cTipo.getSelectedIndex(), jTextField1.getText(), taMensaje.getText(), panelPrincipal.nick);
			VentanaManager ventanaManager = VentanaFactory.getInstance();
			ventanaManager.insertarSugerencia(sugerencia);
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelSugerencias());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);
			}
		}

	}

}